package com.bilin.coin.list;

import android.widget.ImageView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bilin.coin.ApiConstant;
import com.bilin.coin.R;
import com.bilin.coin.bean.MillResourceBean;
import com.bilin.coin.common.base.BaseAppCompatActivity;
import com.bilin.coin.utils.DateUtil;
import com.bilin.coin.utils.DensityUtils;
import com.bilin.coin.utils.GlideUtils;
import com.bilin.coin.utils.GsonUtil;
import com.bilin.coin.utils.SpacesItemDecoration;
import com.bilin.coin.widget.AbsPullToRefreshRecycleView;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class MillResourceList extends AbsPullToRefreshRecycleView<MillResourceBean> {


    public MillResourceList(BaseAppCompatActivity activity) {
        super(activity, true, false, true);
    }

    @Override
    public int fillPageSize() {
        return 100;
    }

    @Override
    public boolean isPost() {
        return false;
    }

    @Override
    public List parseListDataAndFillTotal(String dataJson) {
        List<MillResourceBean> memberBean = GsonUtil.jsonToList(dataJson, MillResourceBean.class);
        //totalCount = memberBean.getTotal();
        return memberBean;
    }

    @Override
    public Map<String, String> fillParams() {
        HashMap params = new HashMap();
        params.put("currentPage", page + "");
        params.put("pageSize", pageSize + "");
        return params;
    }

    @Override
    protected RecyclerView.LayoutManager fillLayoutManger() {
        LinearLayoutManager manager = new LinearLayoutManager(activity);
        manager.setOrientation(RecyclerView.VERTICAL);
        recyclerView.addItemDecoration(new SpacesItemDecoration(1, DensityUtils.dp2px(activity, 10), 0x1888));
        return manager;
    }

    @Override
    public String fillUrl() {
        return "/api/bl-device/list";
    }

    @Override
    protected void convertItem(BaseViewHolder helper, MillResourceBean item) {

        ImageView ivIcon = helper.getView(R.id.iv1);
        try {
            if (item.getImgUrl().startsWith("http")) {
                //GlideUtils.getInstance().displayCurrencyImage(activity, item.getCoverUrl(), ivIcon,800,800);
                GlideUtils.getInstance().displayCurrencyImage(activity, item.getImgUrl(), ivIcon);
            } else {
                //GlideUtils.getInstance().displayCurrencyImage(activity, ApiConstant.OSSURL + item.getCoverUrl(), ivIcon,800,800);
                GlideUtils.getInstance().displayCurrencyImage(activity, ApiConstant.OSSURL + item.getImgUrl(), ivIcon);
            }

        } catch (Exception e) {
            e.printStackTrace();
        }

        helper.setText(R.id.tv_cost, "租赁所需数量：金豆"+item.getCostJd()+"枚");
        helper.setText(R.id.tv_mill_name, ""+item.getName());
        helper.setText(R.id.tv_total_reward, ""+item.getAwardJd());
        helper.setText(R.id.tv_daily_reward, ""+item.getAwardZz());
        helper.setText(R.id.tv_jx, ""+item.getAwardJx());
        helper.setText(R.id.tv_reward_zz, ""+item.getAwardZz());
        helper.setText(R.id.tv_daily_reward, ""+item.getPerDayAward());
        //helper.setText(R.id.tv_work_time_and_limit, "工作时间:"+ DateUtil.getDiffDDHHMMSS2(Long.parseLong(item.getWorkTime())*1000+"")+"       有效期:"+item.getValidDay()+"天");
        //helper.setText(R.id.tv_work_time_and_limit, "工作时间:"+ item.getWorkTimeStr()+"       有效期:"+item.getValidDay()+"天");
        helper.setText(R.id.tv_work_time_and_limit, "工作时间："+ item.getWorkTimeStr()+"  "+item.getValidDayStr()+"");

        helper.addOnClickListener(R.id.bt_buy);
    }

    @Override
    protected int fillAnimationType() {
        return BaseQuickAdapter.ALPHAIN;
    }

    @Override
    protected int fillItemLayout() {
        return R.layout.item_my_mill_resource;
    }
}
